package com.mogu.blogs.controller;

import com.alipay.api.AlipayApiException;
import com.mogu.blogs.service.BlogContentService;
import com.mogu.blogs.utils.AlipayUtils;
import com.mogu.entity.TBlog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by 45795 on 2020/5/27.
 */

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private AlipayUtils alipayUtils;
    @Autowired
    private BlogContentService blogContentService;

    @GetMapping("/blog/{uid}")
    public String pay(@PathVariable String uid){
        System.out.println("----------------");
        TBlog blogByUid = blogContentService.getBlogByUid(uid);

        String pay="";
        try {
            alipayUtils.setAmount("50");
            alipayUtils.setNumber("121212121212");
            alipayUtils.setSubject("打赏给："+blogByUid.getTitle()+"   作者："+blogByUid.getAuthor());
            pay = alipayUtils.pay();
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        System.out.println(pay);
        return pay;
    }

}
